(function () {
    var core = ecui,
        util = core.util,
        dom = ecui.dom;
    ecui.util.extend(
        NS.ui,
        {
            ContractCommentSave: core.inherits(
                mao.ui.CommentSave,
                {
                    onsubmit: function () {
                        if (this._oRequest) {
                            return;
                        }
                        this._oRequest = true;
                        var form = this.getInput().form;
                        if (this.action === '7') {
                            // 评论
                            ecui.esr.request(
                                'data@JSON /erp-management/contract/comment?id=' + form.id.value + '&comment=' + form.actionRemark.value,
                                function () {
                                    this._oRequest = false;
                                    var data = ecui.esr.getData('data');
                                    if (data instanceof Object) {
                                        ecui.tip('warn', '评论成功');
                                        ecui.esr.getRoute('detail.contract').CACHE = false;
                                        ecui.esr.callRoute(util.stringFormat('detail.contract~orderSn={0}~moduleType={1}~initiate={2}', ecui.esr.getData('orderSn'), ecui.esr.getData('moduleType'), ecui.esr.getData('initiate')));
                                    }
                                }.bind(this),
                                function () {
                                    this._oRequest = false;
                                }.bind(this)
                            );
                        } else if (this.action === '6') {
                            // 删除
                            ecui.esr.request(
                                'data@FORM /erp-management/contract/delete?' + form.name,
                                function () {
                                    this._oRequest = false;
                                    var data = ecui.esr.getData('data');
                                    if (data instanceof Object) {
                                        ecui.tip('warn', '删除成功');
                                        ecui.esr.getRoute('/approval/initiate.initiate').CACHE = false;
                                        history.go(-1);
                                    }
                                }.bind(this),
                                function () {
                                    this._oRequest = false;
                                }.bind(this)
                            );
                        } else if (this.action === '5') {
                            // 编辑
                        } else {
                            // 0-撤销 1-提交 2-驳回 3-通过 4-中止
                            var tip = ['撤销', '提交', '驳回', '通过', '中止'];
                            ecui.esr.request(
                                'data@FORM /erp-management/contract/action?' + form.name,
                                function () {
                                    this._oRequest = false;
                                    var data = ecui.esr.getData('data');
                                    if (data instanceof Object) {
                                        ecui.tip('warn', tip[+this.action] + '成功');
                                        if (ecui.esr.getData('initiate') === 'true') {
                                            ecui.esr.getRoute('/approval/initiate.initiate').CACHE = false;
                                        } else {
                                            ecui.esr.getRoute('/approval/approve').CACHE = false;
                                        }
                                        history.go(-1);
                                    }
                                }.bind(this),
                                function () {
                                    this._oRequest = false;
                                }.bind(this)
                            );

                        }
                    }
                }
            )
        }
    );
    ecui.esr.addRoute('contract', {
        model: ['detail@GET /erp-management/contract/${orderSn}?msgId=${msgId}'],
        weight: 4,
        main: 'approval_detail-contract',
        view: 'detail.contract',
        frame: true,
        CACHE: false,
        onbeforerequest: function (context) {
        },
        onbeforerender: function (context) {
            var title = ['', '的包场合同申请', '的分票合同申请', '的商务合同申请', '的自办项目申请'];
            if (context.detail) {
                var title = context.detail.contractInfo.delegateStaffName + title[context.moduleType || context.detail.contractInfo.type];
                ecui.esr.setData('contractTitle', title);
                mao.util.setTitle(title);
                // context.detail.actionCuttingName = context.detail.actionCutting.map(function (item) { return item.name; }).join('，');
                // context.detail.musiciansName = context.detail.musicians.map(function (item) { return item.name; }).join('，');
                context.detail.deptName = context.detail.dept.map(function (item) { return item.name; }).join(' - ');
            }
        }
    });
}());